<!DOCTYPE html>
<html>

	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title>swiper</title>
		<link rel="stylesheet" href="../css/font-icons.css">
		<link rel="stylesheet" href="../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../css/swiper.min.css">
		<link rel="stylesheet" type="text/css" href="../css/iuapmobile.um.listview.css">
		<script src="../js/summer.js"></script>
		<script src="../js/jquery.min.js"></script>
		<script src="../js/Myjs/Common.js"></script>
		<script src="../js/Frameworks/iuapmobile.frameworks.ui.js"></script>
		<script src="../js/idangerous.swiper2.7.6.min.js"></script>
		<script src="../js/angular.min.js"></script>
		<style>
			.swiper-slide h1,
			.swiper-slide h2 {
				color: white;
			}
			
			.um-header {
				background: transparent;
			}
			
			.um-header-outside {
				background-color: transparent;
				position: fixed;
				left: 0;
				top: 0;
				width: 100%;
				min-height: 44px;
				z-index: 99;
			}
			
			.um-footer-outside {
				background-color: #f9f9f9;
				position: fixed;
				left: 0;
				bottom: 0;
				width: 100%;
				z-index: 99;
			}
			
			.selfclass {
				height: 80px;
				padding-top: 10px;
			}
			
			#me {
				min-height: 83px;
			}
		</style>
		<script type="text/javascript" src="../js/knockout.js"></script>
		<script type="text/javascript" src="../js/Frameworks/iuapmobile.frameworks.listview.js"></script>
	</head>

	<body>
		<div style="min-height:400px" class="um-win" id="home">
			<div id="content" class="um-content um-box">
				<div class="swiper-container um-bf1" id="box">
					<div class="swiper-wrapper" id="swiper">
						<div id="page1" class=" swiper-slide page1" style="width: 100%">
							<!-- 导航栏
							<div class="um-header" style="background-color: RGB(157,174,61)">
							<h3>设备管理APP</h3>
							</div>
							-->
							<img id="banner" src="../img/myimg/banner0.png" width="100%" alt="" />
							<!-- 控件集 -->
							<div id="me" class="um-grid um-row">
								<!--<div class="um-grid-row tc um-border-bottom">
								<div class="um-border-right um-bgc-white">
								<a href="#" class="um-circle um-black"> <img src="../img/mt_mv.png" width=40 class="um-img-responsive" alt="">
								<div  class="f12 mt5">
								电影
								</div> </a>
								</div>

								</div>-->
							</div>
							<!-- 测试区 -->
							<div id="magTitle" class="um-list mt5" style="border: none">
								<div class="um-list-item">
									<div class="um-list-item-media">
										<img src="../img/myimg/msg.png" width=24 class="um-round" alt="">
									</div>
									<div class="um-list-item-inner">
										<div class="um-list-item-body">
											消息中心
										</div>
									</div>
								</div>
							</div>
							<div class="um-listview-wrap " id="listview">
								<div class="hd1 pt15 pb15 f15" style="text-align: center;">
									<span class="ti-reload hd1">没有找到数据 点击刷新</span>
								</div>
								<ul id="listitem" class="um-list um-no-active" data-bind="foreach:data">
									<li class="um-listview-row">
										<a class="um-list-item um-swipe-action um-no-icon">
											<div class="um-swipe-btns">
												<span class="um-swipe-btn um-delete">删除</span>
											</div>
											<div class="um-list-item-media">
												<label class="um-check-inline um-list-left-icon">
												<input name="um-checkbox-inline" type="checkbox">
												<span class="um-icon-checkbox um-css3-vc"></span> </label>
											</div>
											<div class="um-list-item-inner">
												<div class="um-list-item-body" style="padding-right:0">
													<div class="clearfix f12">
														<div class="um-xs-6 tl um-text-overflow">
															<span data-bind="text:messageType"></span>
														</div>
														<div class="um-xs-6 tr um-text-overflow">
															<span data-bind="text:thistime"></span>
														</div>
													</div>
													<div class="clearfix mt5 f12">
														<div class=" tl">
															<span data-bind="text:context" class="um-gray"></span>
														</div>
													</div>
												</div>
											</div>
										</a>
									</li>
								</ul>
								<p id="lookMore" style="text-align: center;margin-top: 10px;margin-bottom: 10px;" onclick="updateMsg(msgindex, 4);sender.refresh();">查看更多</p>
							</div>
							<div style="height: 1px;margin-top: 40px;"></div>
						</div>
						<div class="swiper-slide page2" ng-app="myApp" ng-controller="myCtrl">
							<div class="um-header" style="background-color: RGB(157,174,61)">

								<h3>个人中心</h3>
							</div>

							<img src="../img/myimg/home_banner.png" width=100% alt="" class="um-img-responsive">

							<div class="um-list" style="border: none">

								<div class="um-list-item" style="height: 40px">
									<div class="um-list-item-media">
										<img src="../img/myimg/name.png" width=24 class="um-round" alt="">
									</div>
									<div class="um-list-item-inner">
										<div class="um-list-item-body">
											姓名
										</div>
										<div class="um-list-item-right">
											<span class="um-gray mr15" ng-model="empName">{{empName}}</span>
										</div>
									</div>
								</div>
								<div class="um-list-item" style="height: 40px">
									<div class="um-list-item-media">
										<img src="../img/myimg/department.png" width=24 height=24 class="um-round" alt="">
									</div>
									<div class="um-list-item-inner">
										<div>
											部门
										</div>
										<div class="um-list-item-right">
											<span class="um-gray mr15" ng-model="departMent">{{departMent}}</span>
										</div>
									</div>
								</div>
								<div class="um-list-item" style="height: 40px">
									<div class="um-list-item-media">
										<img src="../img/myimg/Contact.png" width=24 class="um-round" alt="">
									</div>
									<div class="um-list-item-inner">
										<div class="um-list-item-body">
											联系方式
										</div>
										<div class="um-list-item-right">
											<span class="um-gray mr15" style="border: none" ng-model="phone">{{phone}}</span>
										</div>
									</div>
								</div>

							</div>

							<div class="um-list " onclick="updateApp();" style="height: 50px;border-top: none">
								<div class="um-list-item">
									<div class="um-list-item-media">
										<img src="../img/myimg/update.png" width=24 class="um-round" alt="">
									</div>
									<div class="um-list-item-inner" style="border-top:1px solid RGB(216,216,216)">
										<div class="um-list-item-body">
											版本更新
										</div>
										<div class="um-list-item-right" style="border: none">
											<span class="um-gray mr15" style="border: none" ng-model="version">{{version}}</span>
										</div>
									</div>
								</div>
							</div>
							
							<button onclick="flushFiles()" ; class="btn" style="width:90%;margin:7% 5% 0 5%;background-color: #FFD700;border: none;color:#FFFFFF">
								清理缓存
							</button>
							<button onclick="loginOut()" ; class="btn" style="width:90%;margin:1% 5% 0 5%;background-color: RGB(224,25,6);border: none;color:#FFFFFF">
								退 出
							</button>
							

						</div>

					</div>
				</div>
			</div>
		</div>
		<div id="footer" class="um-footer-outside">
			<div class="um-footerbar">
				<a id="item0" href="#" class="um-footerbar-item active" data-index="0"> <i class="ti-comments f20"></i>
					<div class="f12 lh1">
						主页
					</div>
				</a>
				<a id="item1" href="#" class="um-footerbar-item " data-index="1"> <i class="ti-notepad f20"></i>
					<div class="f12 lh1">
						个人中心
					</div>
				</a>
			</div>
		</div>
		<script>
			var mySwiper = new Swiper('.swiper-container', {
				direction: 'horizontal',
				loop: false,
				onSlideChangeEnd: function(swiper) {
					$("a[data-index='" + swiper.activeIndex + "']").addClass("active").siblings().removeClass("active");
					//切换header内容
					changeTitle(swiper.activeIndex);
				}
			});

			function changeTitle(index) {
				var titles = {
					'0': function() {
						return '消息'
					},
					'1': function() {
						return '日程'
					}
				}
				if(typeof titles[index] !== 'function') {
					return false;
				}
				return $('.um-header-outside h1').html(titles[index]());
			}

			//footer点击切换页面
			$('.um-footerbar').on('click', '.um-footerbar-item', function(e) {
				mySwiper.swipeTo($(e.currentTarget).index(), 300, false);
				changeTitle($(e.currentTarget).index());
			});
			var arr = new Array();

			var container = document.getElementById("me");
			var updateMsg;
			var anguluarscope;

			function initcomponents() {
				var permssion = summer.getStorage('userinfo').rolePermissions;
				//var array = ["app001", "app002", "app003", "app004", "app005", "app006", "app007", "app010", "app011", "app012", "app013", "app014", "app015", "app016"]
				var array = permssion.split(",");
				for(var l = 0; l < array.length; l++) {
					if(modellist[array[l]]) {
						arr.push({
							icon: array[l],
							label: modellist[array[l]]
						});

					}
				}
				init();
			};
			/**
			 * ===============
			 */
			//initcomponents()
			/**
			 * ------------
			 */
			function change(arrlist, index) {
				var temp;
				if(index === 0 || index > arrlist.length - 1) {
					return arrlist;
				}
				temp = arrlist[index];
				arrlist[index] = arrlist[index - 1];
				arrlist[index - 1] = temp;
				return arrlist;
			}

			function init() {
				for(var k = 0; k < arr.length; k++) {
					var pearsent = document.createElement("div");
					pearsent.className = "tc";
					pearsent.style.backgroundColor = "#FFFFFF";
					var son = document.createElement("div");
					son.className = "selfclass  um-bgc-white";
					son.style.float = "left";
					son.style.width = (window.innerWidth / 4) + "px";
					var link = document.createElement("a");

					///////////////////////
					link.setAttribute("data", arr[k].label);
					link.addEventListener("click", function(d) {
						var ides = "";
						var url = "";
						switch(this.getAttribute("data")) {
							case "接收派工":
								ides = "install";
								url = "html/install/install.html";
								break;
							case "商家拓展":
								ides = "shangjiatuozhan";
								url = "html/ShangJiaCaiJi/insert.html";
								break;
							case "拓展查看":
								ides = "shangjiatuozhanlist";
								url = "html/ShangJiaCaiJi/list.html";
								break;
							case "施工验收":
								ides = "AnZhuangYanShouList";
								url = "html/AnZhuangYanShou/main.html";
								break;
							case "设备实发":
								ides = "ActualMain";
								url = "html/Actual/ActualMain.html";
								break;
							case "设备签收":
								ides = "qianshoulist";
								url = "html/qianshoulist.html";
								break;
							case "施工完成":
								ides = "Constructionlist";
								url = "html/inspected/Constructionlist.html";
								break;
							case "拆机派工":
								ides = "disassemble";
								url = "html/disassemble/disassemble.html";
								break;
							case "拆机实收":
								ides = "disassemble_in";
								url = "html/disassemble_in/disassemble_in.html";
								break;
							case "维修派工":
								ides = "repair";
								url = "html/repair/repair.html";
								break;
							case "维修完成":
								ides = "Constructionlist";
								url = "html/repair_finish/Constructionlist.html";
								break;
							case "维修验收":
								ides = "WeiXiuYanShouList";
								url = "html/repair_check/repaircheckList.html";
								break;
							case "设备入库":
								ides = "device_in";
								url = "html/device_in/device_in.html";
								break;
							case "设备出库":
								ides = "device_out";
								url = "html/device_out/device_out.html";
								break;
							case "设备盘点":
								ides = "shangjiatuozhan";
								url = "html/devcie_inventory/insert.html";
								break;
						    case "现场勘察":
						    	ides = "xianchangkancha";
								url = "html/xianchangkancha/list.html";
						        break;
						}

						summer.openWin({
							id: ides,
							url: url,
							isKeep: true,
							reload: true
						});
					}, false);
					///////////////////////
					link.href = "#";
					link.className = "um-circle um-black";
					var img = document.createElement("img");
					img.src = "../img/myimg/" + arr[k].icon + ".png";
					img.width = 40;
					img.className = "um-img-responsive";
					var label = document.createElement("div");
					label.className = "f12 mt5";
					label.innerHTML = arr[k].label;
					link.appendChild(img);
					link.appendChild(label);
					son.appendChild(link);
					var conitem = document.getElementsByClassName("tc");
					if(conitem.length == 0) {
						pearsent.appendChild(son);
						container.appendChild(pearsent);

					} else {
						for(var i = 0; i < conitem.length; i++) {
							var len = conitem[i].children.length;
							for(var j = 0; j < len; j++) {
								if(len < 4) {
									container.children[i].appendChild(son);

								} else {
									pearsent.appendChild(son);
									container.appendChild(pearsent);
								}
							}

						}
					}

				};
				//
				/*
				 *  快捷方法
				 *var node = document.getElementsByClassName("tc")[0].children;
				 for (var j = 0; j < node.length; j++) {
				 node[i].onclick = (function(k){
				 return function(){
				 summer.openWin({
				 id: arr[i].icon,
				 url:"html/"+arr[i].icon+"/"+arr[i].icon+".html",
				 isKeep:true
				 });
				 }
				 })(i)
				 }*/
			}

			//版本升级
//			function downloadCallBack(args) { //下载完成
//				console.log(args);
//				if(args.isfinish == true){
//					summer.installApp(args.savePath);
//				}
//			}
			function updateApp(boo) {
				var shebei = "ANDROID";
				if(summer.getSysInfo().systemType != "android") {
					shebei = "IOS";
				}

				$.ajax({
					timeout: 10000, //超时时间设置10秒
					type: 'POST',
					url: summer.getStorage("serverAdress") + "/Axis2Api/AppVersion",
					data: {
						"data": JSON.stringify({
							platform: shebei
						})
					},
					success: function(response) {
						response = JSON.parse(response);
						if(response.data) {
							var versionAndMiaoShu = response.data.APPVERSION.split("&");
							var miaoshu = "修复了部分BUG";
							var banbenhao = versionAndMiaoShu[0];
							if(versionAndMiaoShu.length > 1){
								try{
									miaoshu = unescape(versionAndMiaoShu[1]);
								}catch(e){}
							}
							if(banbenhao != JSON.parse(summer.getAppVersion()).versionName) {
								UM.confirm({
									title: '发现新版本,请尽快更新',
									text: miaoshu,
									btnText: ["下次再说", "更新"],
									overlay: true,
									ok: function() {
										summer.openWebView({
											url : response.data.APPUPDATEURL
										});
									},
									cancle: function() {}
								});

							} else {
								if(!boo){
									alerts("已经是最新版本");
								}
							}
						}
					},
					error: function(e) {
						alert("获取服务器出错，请稍后再试");
					},
				});
			}
			
			function flushFiles(){		
				if(!!summer.getStorage("adressPaiZhao")){
					summer.callService("UMFile.getChildList", { //
						"filepath": summer.getStorage("adressPaiZhao"),
						"callback": function(arg) {
							var aa = JSON.parse(arg.filelist);
							for(var i=0;i<aa.length;i++){
								summer.removeFile({
									path : arg.filepath,
									file : aa[i].name,
									callback : "deleteImgBack()"
								});
							}
						}
					}, false);
				}
				if(!!summer.getStorage("adressYaSuo")){
					summer.callService("UMFile.getChildList", { //
						"filepath": summer.getStorage("adressYaSuo"),
						"callback": function(arg) {
							var aa = JSON.parse(arg.filelist);
							for(var i=0;i<aa.length;i++){
								summer.removeFile({
									path : arg.filepath,
									file : aa[i].name,
									callback : "deleteImgBack()"
								});
							}
						}
					}, false);
				}
				if(!!summer.getStorage("adressXuanZhuan")){
					summer.callService("UMFile.getChildList", { //
						"filepath": summer.getStorage("adressXuanZhuan"),
						"callback": function(arg) {
							var aa = JSON.parse(arg.filelist);
							for(var i=0;i<aa.length;i++){
								summer.removeFile({
									path : arg.filepath,
									file : aa[i].name,
									callback : "deleteImgBack()"
								});
							}
						}
					}, false);
				}
				if(!!summer.getStorage("adressXiaZai")){
					summer.callService("UMFile.getChildList", { //
						"filepath": summer.getStorage("adressXiaZai"),
						"callback": function(arg) {
							var aa = JSON.parse(arg.filelist);
							for(var i=0;i<aa.length;i++){
								summer.removeFile({
									path : arg.filepath,
									file : aa[i].name,
									callback : "deleteImgBack()"
								});
							}
						}
					}, false);
				}
				setTimeout(function() {
					alerts("已执行清理");
				},1000);
			}
			function deleteImgBack(a,b){
				var asdsad = "";
			}

			function loginOut() {
				UM.confirm({
					title: '友情提示：',
					text: '是否退出登录？',
					btnText: ["取消", "退出"],
					overlay: true,
					ok: function() {
						summer.setStorage('username', "");
						summer.setStorage('password', "");
						summer.setStorage('userinfo', "");
						//						summer.execScript({
						//							winId: "Login",
						//							//frameId:"",
						//							script: "inits()"
						//						});
						summer.closeWin();
						//						summer.openWin({
						//							id : "Login",
						//							url : "html/Login.html",
						//							isKeep : false,
						//							reload : false
						//						});
					},
					cancle: function() {
						$(".um-modal-in").css("display", "none");
					}
				});
			}

			var app = angular.module('myApp', []);
			app.controller('myCtrl', function($scope) {
				anguluarscope = $scope;
			});

			var msgindex = 1;
			$(function() {
				var arrs = [];
				var ViewModel = function() {};
				var viewModel = new ViewModel();
				var listview = UM.listview("#listview");
				viewModel.data = ko.observableArray([]);
				ko.applyBindings(viewModel);

				updateMsg = function(index, cout) {
					doPost(adressHead.ISjtzImpl, "getJkxxList", {
						dataParm: {
							empId: summer.getStorage('userinfo').empId,
							star: index,
							count: cout
						}
					}, function(data) {
						if(index == 1) {
							try {
								while(viewModel.data.shift()) {}
							} catch(e) {}
						};
						if(data.result == 1) {
							if(data.data.length != "") {
								$(".hd1").css("display", "none"); //hide
								for(var i = 0; i < data.data.length; i++) {
									console.log("aaaa" + data.data[i]);
									var msgtype = parseInt(data.data[i].type) - 1;
									viewModel.data.push({
										'context': data.data[i].context,
										'type': data.data[i].type,
										'messageId': data.data[i].messageId,
										'thistime': data.data[i].thistime.substr(0, 10),
										'messageType': msgTypeList[msgtype]
									});
								};
								//initDom(index);
								msgindex += data.data.length;
							} else {
								$(".hd1").css("display", "block"); //hide
								UM.toast({
									title: '友情提示：',
									text: '没有更多消息',
									duration: 1000
								});
							}
						} else {
							UM.toast({
								title: '友情提示：',
								text: data.msg,
								duration: 1000
							});
						}
						listview.refresh();
					}, function(err) {
						console.log(err);
					});
				};
				/**
				 * ------------
				 */
				//updateMsg(1,3)
				/**
				 * -----------
				 */
				$(".hd1").click(function(e) {
					updateMsg(1, 4);
					e.stopPropagation();
				});
				//添加控件方法
				listview.on('pullDown', function(sender) {
					msgindex = 1;
					updateMsg(msgindex, 4);
				});
				//listview.on('pullUp', function(sender) {
				//	updateMsg(msgindex, 3);
				//	sender.refresh();
				//});
				listview.on("itemDelete", function(sender, args) {
					var item = viewModel.data()[args.rowIndex];
					if(item.type == "4") {
						args.$target.slideUp(500, function() {
							viewModel.data.remove(item);
						});
						var userinfo = summer.getStorage("userinfo");
						doPost(adressHead.ISjtzImpl, "deleteSjtzd", {
							dataParm: {
								empId: userinfo.empId,
								billcode: viewModel.data()[args.rowIndex].messageId
							}
						}, function(jsons) {
							toasts(jsons.msg);
							if(jsons.result == 1) {
								updateMsg(1, 4);
							}
						});
					} else {
						UM.toast({
							title: '友情提示：',
							text: "此消息不能删除",
							duration: 1000
						});
					}
				});
				listview.on("itemSwipeLeft", function(sender, args) {
					sender.showItemMenu(args.$target);
				});
				listview.on('itemClick', function(sender, args) {
					MessageJunp(viewModel.data()[args.rowIndex]);
				});
			});
			summerready = function() {
				anguluarscope.version = "v" + JSON.parse(summer.getAppVersion()).versionName;
				var data = summer.getStorage('userinfo');
				for(var i in data) {
					anguluarscope[i] = data[i];
					anguluarscope.$apply();
				}
				setTimeout(function(){
					updateApp(true);
				},500);
				initcomponents();
				updateMsg(1, 4);
			};
			
			//{pageid:"",pageurl:"",cs:""}
			function change(obj){	
				setTimeout(function() {
					summer.openWin({
						id: obj.pageid,
						url: obj.pageurl,
						isKeep: true,
						reload: true,
						pageParam:obj.cs
					});
				},500);
			}
			
			function keyBack(){
				UM.confirm({
					title: '东方天呈',
					text: '是否退出软件？',
					btnText: ["取消", "退出"],
					overlay: true,
					ok: function() {
						summer.exitApp()
					},
					cancle: function() {
					}
				});
			};
		</script>
	</body>

</html>